package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.bean.User;
import com.itheima.dao.UserDao;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    //注入dao类的对象
    @Autowired
    private UserDao userDao;
    @Override
    public User add(String phone) {
        //添加要补充数据，先创建有给user对象
        User user = new User();
        //补充状态
        user.setStatus(1);
        //将手机号添加到user对象中
        user.setPhone(phone);
        //调用dao进行对数据库进行添加
        userDao.insert(user);
        return user;
    }

    @Override
    public User findByPhone(String phone) {
        //创建条件对象
        LambdaQueryWrapper<User> qw = new LambdaQueryWrapper<>();
        //设置查询条件
        qw.eq(User::getPhone,phone);
        //调用dao进行查询并返回查询到的user对象
        return userDao.selectOne(qw);
    }

    @Override
    public User findById(Long id) {
        return userDao.selectById(id);
    }
}
